/**
 * Copyright 2007-2010 非也
 * All rights reserved. 
 * 
 * This library is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License v3 as published by the Free Software
 * Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along
 * with this library; if not, see http://www.gnu.org/licenses/lgpl.html.
 *
 */
package org.fireflow2.designer.eclipse.parts.tree;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;

import org.eclipse.gef.editparts.AbstractTreeEditPart;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.fireflow2.designer.eclipse.Activator;
import org.fireflow2.designer.eclipse.modelwrapper.AbsWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.Wrapper;
import org.fireflow2.designer.eclipse.modelwrapper.collection.ServiceListWrapper;

/**
 *
 * @author 非也 nychen2000@163.com
 * Fire Workflow 官方网站：www.firesoa.com 或者 www.fireflow.org
 *
 */
public class ServiceListTreePart  extends AbstractTreeEditPart implements
		PropertyChangeListener {
	private Image foldClose = null;
	private Image foldOpen = null;
	public ServiceListTreePart(){
		ImageDescriptor imageDescriptor = ImageDescriptor.createFromFile(Activator.class, "resources/serviceList.png");
		foldClose = imageDescriptor.createImage();
		
		imageDescriptor = ImageDescriptor.createFromFile(Activator.class, "resources/serviceList.png");
		foldOpen = imageDescriptor.createImage();
	}		
	
	protected List getModelChildren() {
		return ((Wrapper) getModel()).getChildren();
	}
	
	protected void refreshVisuals() {
		this.setWidgetText(((ServiceListWrapper) getModel()).getDisplayName());
		this.setWidgetImage(foldClose);
	}
	
	public void propertyChange(PropertyChangeEvent evt) {
		this.refresh();

	}
	public void activate() {
		if (isActive()) {
			return;
		}
		super.activate();
		((AbsWrapper) getModel()).addPropertyChangeListener(this);
	}

	public void deactivate() {
		if (!isActive()) {
			return;
		}
		super.deactivate();
		((AbsWrapper) getModel()).removePropertyChangeListener(this);
	}
}
